package com.tanhua.model.CommentBackstage;

import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.mongo.Comment;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class CommentVoToBackstage implements Serializable {

    private String id; //评论id
    private String nickname; //昵称
    private Integer uderId;//用户Id
    private String content; //评论
    private Long createDate; //评论时间

    public static CommentVoToBackstage init(UserInfo userInfo, Comment comment) {
        CommentVoToBackstage vo = new CommentVoToBackstage();
        //添加评论id
        vo.setId(String.valueOf(comment.getId()));
        BeanUtils.copyProperties(userInfo, vo);
        BeanUtils.copyProperties(comment, vo);
        vo.setUderId(Math.toIntExact(userInfo.getId()));
        vo.setCreateDate(comment.getCreated());
        return vo;
    }
}